-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
some workload mode bugfix and waypoint optimization #361
Conversation
c2d6b8e
to
3d897b5
Compare
log.Warnf("current only supprt single ip of a pod") | ||
} | ||
|
||
for _, ip := range workload.GetAddresses() { // current only support signle ip, if a pod have multi ips, the last one will be stored finally |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will multiple IPs be supported later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if support is needed in the future, but currently it's not supported.
bv.Services[bv.ServiceCount] = p.hashName.StrToNum(serviceName) | ||
bv.ServiceCount++ | ||
if bv.ServiceCount >= bpf.MaxServiceNum { | ||
log.Warnf("exceed the max service count, currently, a pod can belong to a maximum of 10 services") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to put the serviceName in warnning here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what you meant don't understand
Don't use force-push if you don't have to, in case someone else is reviewing it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kwb0523 Please update the proposal doc as well to facilitate review
) | ||
|
||
bk.BackendUid = uid | ||
if err = p.bpf.BackendLookup(&bk, &bv); err == nil { | ||
if err := p.bpf.BackendLookup(&bk, &bv); err == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'd better log the err
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
addr := waypoint.GetAddress().Address | ||
bv.WaypointAddr = nets.ConvertIpByteToUint32(addr) | ||
bv.WaypointPort = nets.ConvertPortToBigEndian(waypoint.GetHboneMtlsPort()) | ||
bv.IPv4 = nets.ConvertIpByteToUint32(ip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the byte order now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
little endian, always like this.
LbPolicy uint32 // load balancing algorithm, currently only supports random algorithm | ||
EndpointCount uint32 // endpoint count of current service | ||
LbPolicy uint32 // load balancing algorithm, currently only supports random algorithm | ||
ServicePort ServicePorts // ServicePort[i] and TargetPort[i] are a pair, i starts from 0 and max value is MaxPortNum-1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, it's better to define a PortPair
data struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently,we use cilium bpf interface to operate the map, and the interface cannot support self defined data struct.
|
||
for i, port := range ports { | ||
if i >= bpf.MaxPortNum { | ||
log.Warnf("exceed the max port count,current only support maximum of 10 ports") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls record detailed log information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
} | ||
|
||
sv.ServicePort[i] = nets.ConvertPortToBigEndian(port.ServicePort) | ||
if strings.Contains(serviceName, "waypoint") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe incorrect judgment if ServiceName contains waypoint
, but actually it is not waypoint
service. FYI, it is no need to check each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, there is indeed such a problem at present, and we will track the relevant optimization situation through this issue #370 in the future.
|
||
if waypoint != nil { | ||
sv.WaypointAddr = nets.ConvertIpByteToUint32(waypoint.GetAddress().Address) | ||
sv.WaypointPort = nets.ConvertPortToBigEndian(waypoint.GetHboneMtlsPort()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waypoint.GetHboneMtlsPort() -> KmeshWaypointPort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here stored are ip and port of a waypoint service, not the waypoint backend port info.
bv.IPv4 = nets.ConvertIpByteToUint32(ip) | ||
bv.ServiceCount = 0 | ||
for serviceName := range portList { | ||
bv.Services[bv.ServiceCount] = p.hashName.StrToNum(serviceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the code, some Map such as endpointsByService
using serviceName(string key) for store, however, call StrToNum when map is read. If the map is directly stored by number, conversion is not required and more efficiency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mainly about the optimization related to endpointsByService, which may be carried out later and is not related to the current PR processing problem.
bpf/kmesh/workload/include/backend.h
Outdated
BPF_LOG(DEBUG, BACKEND, "access the backend by service:%d \n", service_id); | ||
#pragma unroll | ||
for (__u32 j = 0; j < MAX_PORT_COUNT; j++) { | ||
if (service_v->service_port[j] != 0 && user_port == service_v->service_port[j]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
service_v->service_port[j] != 0 -- no need to check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
bpf/kmesh/workload/include/backend.h
Outdated
} | ||
} | ||
|
||
BPF_LOG(ERR, BACKEND, "failed to get the backend\n"); | ||
return -ENOENT; | ||
} | ||
|
||
// access the backend directly | ||
static inline int direct_backend_manager(ctx_buff_t *ctx, backend_value *backend_v) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This layer of function encapsulation seems unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
bpf/kmesh/workload/include/backend.h
Outdated
{ | ||
int ret; | ||
address_t target_addr; | ||
__u32 *sk = (__u32 *)ctx->sk; | ||
struct bpf_sock_tuple value_tuple = {0}; | ||
|
||
if (backend_v->waypoint_addr != 0 && backend_v->waypoint_port != 0) { | ||
BPF_LOG(DEBUG, BACKEND, "find waypoint addr=[%u:%u]\n", backend_v->waypoint_addr, backend_v->waypoint_port); | ||
if (addr != 0 && port != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest checking this before calling waypoint_manager, it would be more readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
bpf/kmesh/workload/include/backend.h
Outdated
for (unsigned int i = 0; i < backend_v->port_count; i++) { | ||
if (i >= MAX_PORT_COUNT) { | ||
for (__u32 i = 0; i < backend_v->service_count; i++) { | ||
if (i >= MAX_SERVICE_COUNT) { | ||
BPF_LOG(WARN, BACKEND, "exceed the max port count\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should update the log, max service count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
bpf/kmesh/workload/include/backend.h
Outdated
BPF_LOG(DEBUG, BACKEND, "get the backend addr=[%u:%u]\n", target_addr.ipv4, target_addr.port); | ||
return 0; | ||
if (service_id == backend_v->service[i]) { | ||
BPF_LOG(DEBUG, BACKEND, "access the backend by service:%d \n", service_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\n is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -50,7 +50,7 @@ static inline int frontend_manager(ctx_buff_t *ctx, frontend_value *frontend_v) | |||
} | |||
|
|||
if (direct_backend) { | |||
ret = backend_manager(ctx, backend_v); | |||
ret = direct_backend_manager(ctx, backend_v); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add some comments, this is actually pod direct access, if a pod has watpoint captured, we will redirect to waypoint here. If it is not waypoint captured, we do nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
1.fix potential target port modify error when access backend directly 2.fix a backend that belongs to multi services 3.store waypoint info in service to accelerate waypoint access Signed-off-by: kwb0523 <kwb0523@163.com>
Codecov ReportAttention: Patch coverage is ❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Flags with carried forward coverage won't be shown. Click here to find out more.
|
bpf/kmesh/workload/include/backend.h
Outdated
BPF_LOG(WARN, BACKEND, "exceed the max port count\n"); | ||
for (__u32 i = 0; i < backend_v->service_count; i++) { | ||
if (i >= MAX_SERVICE_COUNT) { | ||
BPF_LOG(WARN, BACKEND, "exceed the max port count:%d\n", MAX_SERVICE_COUNT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong log, it is max service number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm \n
DEBUG, BACKEND, "get the backend addr=[%pI4h:%u]\n", &target_addr.ipv4, bpf_ntohs(target_addr.port)); | ||
return 0; | ||
if (service_id == backend_v->service[i]) { | ||
BPF_LOG(DEBUG, BACKEND, "access the backend by service:%d\n", service_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm \n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that all logs have been added with ‘\n’. Do we need to delete them all together in this PR.
bpf/kmesh/workload/include/backend.h
Outdated
BPF_LOG( | ||
DEBUG, | ||
BACKEND, | ||
"get the backend addr=[%pI4h:%u]\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm \n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
BPF_LOG( | ||
DEBUG, | ||
FRONTEND, | ||
"find waypoint addr=[%pI4h:%u]\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm \n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
bpf/kmesh/workload/include/service.h
Outdated
BPF_LOG( | ||
DEBUG, | ||
SERVICE, | ||
"find waypoint addr=[%pI4h:%u]\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rm \n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Signed-off-by: kwb0523 <kwb0523@163.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
1.fix potential target port modify error when access backend directly
2.fix a backend that belongs to multi services
3.store waypoint info in service to accelerate waypoint access
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: